package no.hio.wsprovider.services;

import java.util.List;
import java.util.NoSuchElementException;

import javax.jws.WebService;

import no.hio.wsprovider.dao.StockItemDAO;
import no.hio.wsprovider.vo.StockItem;

/**
 * @author Henning
 * @version 1.0
 * @see StockItemService
 */
@WebService(name="StockItemService", targetNamespace="http://hio.no/wsproviderstock")
public class StockItemServiceImpl implements StockItemService
{
	StockItemDAO stockItemDAO;
	
	/**
	 * @return the stockItemDAO
	 */
	public StockItemDAO getStockItemDAO() 
	{
		return stockItemDAO;
	}
	
	/**
	 * @param stockItemDAO. The stockItemDAO to set
	 */
	public void setStockItemDAO(StockItemDAO stockItemDAO) 
	{
		this.stockItemDAO = stockItemDAO;
	}
	
	/* (non-Javadoc)
	 * @see no.hio.wsprovider.services.StockItemService#findAllStockItems()
	 */
	@Override
	public List<StockItem> findAllStockItems()
	{
		return stockItemDAO.findAll();
	}

	/* (non-Javadoc)
	 * @see no.hio.wsprovider.services.StockItemService#findByProductID(int)
	 */
	@Override
	public StockItem findByProductID(int productID)
	{
		return stockItemDAO.findByProductID(productID);
	}

	/* (non-Javadoc)
	 * @see no.hio.wsprovider.services.StockItemService#insertStockItem(no.hio.wsprovider.vo.StockItem)
	 */
	@Override
	public void insertStockItem(StockItem stockItem)
	{
		try
		{
			stockItemDAO.insert(stockItem);
		}
		catch(UnsupportedOperationException e)
		{
			//TODO: log exc feil her
		}
	}

	/* (non-Javadoc)
	 * @see no.hio.wsprovider.services.StockItemService#updateStockItem(no.hio.wsprovider.vo.StockItem)
	 */
	@Override
	public void updateStockItem(StockItem stockItem)
	{
		try 
		{
			stockItemDAO.update(stockItem);
		} 
		catch (NoSuchElementException e) 
		{
			//TODO: log exc feil her
			//e.printStackTrace();
		}
	}

	/* (non-Javadoc)
	 * @see no.hio.wsprovider.services.StockItemService#removeStockItem(no.hio.wsprovider.vo.StockItem)
	 */
	@Override
	public void removeStockItem(StockItem stockItem)
	{
		try 
		{
			stockItemDAO.remove(stockItem);
		} catch (NoSuchElementException e) {
			//TODO: logg?
		}
	}
	

}
